package com.qcby.system.api.factory;


import com.qcby.common.core.domain.Result;
import com.qcby.system.api.RemoteFileService;
import com.qcby.system.api.domain.SysFileDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

/**
 * 远程文件回退工厂
 *
 * @author cong.zhen
 * @date 2023/11/20
 */
@Component
@Slf4j
public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileService> {

    @Override
    public RemoteFileService create(Throwable throwable)
    {
        log.error("文件服务调用失败:{}", throwable.getMessage());
        return new RemoteFileService()
        {
            @Override
            public Result<SysFileDTO> upload(MultipartFile file)
            {
                return Result.getServiceError("上传文件失败:" + throwable.getMessage());
            }
        };
    }
}
